﻿using System;
using System.Windows.Forms;
using iTextSharp.text;
using iTextSharp.text.pdf;

namespace 默写
{
    /// <summary>
    /// 词组
    /// </summary>
    public class AWord
    {
        /// <summary>
        /// 构建函数
        /// </summary>
        public AWord(string text)
        {
            Text = text;
            ImageIndex = ImageIndex.Word;
        }
        /// <summary>
        /// 什么词组
        /// </summary>
        public String Text
        {
            get;
            set;
        }

        /// <summary>
        /// 词组图片索引值
        /// </summary>
        /// <value>4</value>
        public ImageIndex ImageIndex
        {
            get;
            set;
        }

        /// <summary>
        /// 生成TreeNode节点
        /// </summary>
        public TreeNodeExt ToNode()
        {
            TreeNodeExt rtnTN = new TreeNodeExt(Text,(int)ImageIndex,(int)ImageIndex);
            rtnTN.Name = Text;
            return rtnTN;
        }

        /// <summary>
        /// 生成当前生字的字符串
        /// </summary>
        public override String ToString()
        {
            return Text;
        }

        /// <summary>
        /// 生成pdf格式内容
        /// </summary>
        public Chunk ToPDF()
        {
            string fontpath = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);
            BaseFont songBF = BaseFont.CreateFont(fontpath + @"\simfang.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            Font songfont = new Font(songBF, 18);
            Chunk chunk = new Chunk(Text+"；", songfont);
            return chunk;
        }

        /// <summary>
        /// 由节点生成ACharacter对象
        /// </summary>
        public static AWord FromNode(TreeNodeExt nodeext)
        {
            AWord aword = new AWord(nodeext.Name);
            return aword;
        }

    }
}
